﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _00_演示程序
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //读取当前路径下的index.html文件
            string path = Application.StartupPath + "\\页面 25.html";

            //加载到webView21控件中
            webView21.Source = new Uri(path);

            // 添加NavigationCompleted事件处理程序
            webView21.NavigationCompleted += WebView21_NavigationCompleted;
        }

        private async void WebView21_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
        {
            if (e.IsSuccess)
            {
                // 为导航按钮添加点击事件处理
                await webView21.ExecuteScriptAsync(@"
                    const btns = document.querySelectorAll('button');
                    for (let btn of btns) {
                        if (btn.innerText.includes('运动控制')) {
                            btn.onclick = function() {
                                window.location.href = '运动控制.html';
                            };
                        }
                        if (btn.innerText.includes('参数设置')) {
                            btn.onclick = function() {
                                window.location.href = '参数设置.html';
                            };
                        }
                        if (btn.innerText.includes('图形显示')) {
                            btn.onclick = function() {
                                window.location.href = '图形显示.html';
                            };
                        }
                    }
                ");
            }
        }
    }
}
